import request from './request'
import { useUserStore } from '../store/modules/user'
// 获取用户列表
export function getUsersList(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/getList',
    method: 'post',
    headers: token,
    data,
  })
}

// 导出客户数据
export function userExportExcel(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/dataExport/userExportExcel',
    method: 'post',
    headers: token,
    data,
    responseType: 'blob',
  })
}

// 新增或修改用户
export function addUser(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/add',
    method: 'post',
    headers: token,
    data,
  })
}

// 批量更改用户状态
export function changeStatus(data: object, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/status',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

// 批量删除用户
export function deleteUser(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/',
    method: 'delete',
    headers: token,
    data,
  })
}

// 分页获取用户级别下拉数据列表
export function levelPageSelect(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/select/user/levelPageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 分页获取用户分类下拉数据列表
export function typePageSelect(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/select/user/typePageSelect',
    method: 'post',
    headers: token,
    data,
  })
}

// 获取用户账号信息
export function getUserInfo(id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/' + id,
    method: 'get',
    headers: token,
  })
}

// 获取用户联系人列表
export function getUserContact(data: any, id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/contact/getUserContact/' + id,
    method: 'post',
    headers: token,
    data,
  })
}

// 新增或修改联系人
export function saveUserContact(data: any, id: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/contact/save/' + id,
    method: 'post',
    headers: token,
    data,
  })
}

// 更改主要联系人
export function changeContact(id: any, userId: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/contact/' + userId,
    method: 'put',
    headers: token,
    params: { id },
  })
}

// 批量删除联系人
export function deleteContact(data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/contact/',
    method: 'delete',
    headers: token,
    data,
  })
}

// 更新客户知识库查看权限
export function updateSelectKnowledgeAuthor(id: any, params: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/user/updateSelectKnowledgeAuthor/${id}`,
    method: 'PUT',
    headers: token,
    params,
  })
}

/**
 * 根据客户分类ID获取知识库类型权限列表
 * @param userTypeId 客户分类ID
 * @param data 搜索对象
 * @returns
 */
export function getSelectKnowledgeAuthorList(userTypeId: any, data: any) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: `/user/type/knowledge/type/getList/${userTypeId}`,
    method: 'post',
    headers: token,
    data,
  })
}

/* -----------基础资料相关  start ---------------  */

// 获取用户设置
export function getUserSet() {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/set/getUserSet',
    method: 'get',
    headers: token,
  })
}

// 保存用户设置
export function saveUserSet(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/set/saveUserSet',
    method: 'put',
    headers: token,
    data,
  })
}

// 获取用户级别列表
export function getLevelList(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/level/getList',
    method: 'post',
    headers: token,
    data,
  })
}

// 新增或修改用户级别
export function saveUserLevel(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/level/save',
    method: 'post',
    headers: token,
    data,
  })
}

// 批量更改用户级别状态
export function changeLevel(data: object, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/level/',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

// 批量删除用户级别状态
export function deleteLevel(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/level/',
    method: 'delete',
    headers: token,
    data,
  })
}

// 获取用户分类列表
export function getTypeList(params: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/type/getList',
    method: 'post',
    headers: token,
    data: params,
  })
}

// 新增或修改用户分类
export function saveUserType(params: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/type/save',
    method: 'post',
    headers: token,
    params,
  })
}

// 批量更改用户分类状态
export function changeType(data: object, status: boolean) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/type/',
    method: 'put',
    headers: token,
    data,
    params: { status },
  })
}

// 批量删除用户分类
export function deleteType(data: object) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/type/',
    method: 'delete',
    headers: token,
    data,
  })
}

/* -----------基础资料相关  end ---------------  */
//根据工单ID获取客户关联信息
export function getUserRelationInfo(workId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/getUserRelationInfo/' + workId,
    method: 'get',
    headers: token,
  })
}
// 获取客户关联的编码商品列表
export function getUserRelationCodeGoodsList(data: object, userId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/getUserRelationCodeGoodsList/' + userId,
    method: 'post',
    headers: token,
    data,
  })
}

// 获取客户关联的工单列表
export function getUserRelationOrderList(data: object, userId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/getUserRelationOrderList/' + userId,
    method: 'post',
    headers: token,
    data,
  })
}
// 根据客户ID获取客户附件
export function getUserAnnex(userId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/annex/getUserAnnex/' + userId,
    method: 'get',
    headers: token,
  })
}
//新增或删除用户附件
export function annexSave(data, userId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/user/annex/save/' + userId,
    method: 'post',
    headers: token,
    data,
  })
}
//根据知识库分类ID获取说明书
export function getInstructionBook(knowledgeTypeId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/instruction-book/getInstructionBook/' + knowledgeTypeId,
    method: 'get',
    headers: token,
  })
}
//根据知识库分类ID获取故障库
export function getFailt(knowledgeTypeId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/fault/getFailt/' + knowledgeTypeId,
    method: 'get',
    headers: token,
  })
}
//根据知识库分类ID获取视频
export function getVideo(knowledgeTypeId) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/knowledge/video/getVideo/' + knowledgeTypeId,
    method: 'get',
    headers: token,
  })
}

/**
 * 分页获取用户下拉数据列表
 * @param {Object} data - 请求参数
 * @param {string} data.factoryId - 关联商家
 * @param {number} data.limit - 每页显示数量
 * @param {string} data.name - 搜索关键词
 * @param {number} data.page - 当面页码
 */
export function getUserPageSelect(data: {
  factoryId: string
  limit: number
  name: string
  page: number
}) {
  const token = {
    'access-token': useUserStore().token,
  }
  return request({
    url: '/select/user/getOrderUserSelect',
    method: 'post',
    headers: token,
    data,
  })
}
